package com.anlu.base.common.file.oss;

import com.anlu.base.common.file.core.FileProperties;
import com.anlu.base.common.file.core.FileTemplate;
import com.anlu.base.common.file.oss.http.OssEndpoint;
import com.anlu.base.common.file.oss.service.OssTemplate;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

@AllArgsConstructor
public class OssAutoConfiguration {

    private final FileProperties fileProperties;



    @Bean
    @Primary
    @ConditionalOnMissingBean(OssTemplate.class)
    @ConditionalOnProperty(name = "file.oss.enable",havingValue = "true")
    public FileTemplate ossTemplate() {
        return new OssTemplate(fileProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(name = "file.oss.info",havingValue = "true")
    public OssEndpoint ossEndpoint(OssTemplate template){
        return new OssEndpoint(template);
    }

}
